package services.common;

import java.util.Date;
import java.util.Map;

import models.common.bean.CompanyUserBean;
import models.common.entity.t_company_info;
import models.common.entity.t_company_info_side;
import models.common.entity.t_credit_limit;
import models.common.entity.t_reddish_black;
import models.common.entity.t_reddish_black.ReddishBlack;

import org.apache.commons.lang.StringUtils;

import services.base.BaseService;

import common.enums.CertificateType;
import common.enums.Client;
import common.enums.IsBlackCompany;
import common.utils.Factory;
import common.utils.LoggerUtil;
import common.utils.ResultInfo;
import common.utils.StrUtil;

import daos.common.CompanyInfoSideDao;

/**
 * 企业信息service
 *
 * @description 
 *
 * @author zhiliang.lan
 * @createDate 2017年4月15日
 */

public class CompanyInfoSideService extends BaseService<t_company_info_side>{
	
	protected CompanyInfoSideDao companyInfoSideDao = Factory.getDao(CompanyInfoSideDao.class);
	
	protected static UserService userService = Factory.getService(UserService.class);
	
	protected static ReddishBlackService reddishBlackService = Factory.getService(ReddishBlackService.class);
	
	protected CompanyInfoSideService(){
		super.basedao = companyInfoSideDao;
	}
	
	/**
	 * 根据user_id查询t_company_info_side副表
	 * 
	 * @param user_id
	 * @return
	 *
	 * @author zhiliang.lan
	 * @createDate 2017年4月15日
	 */
	public t_company_info_side findCompanyInfoSideByUserId(long userId) {
	
		return companyInfoSideDao.findCompanyInfoSideByUserId(userId);
	}
	
	/**
	 * 修改企业基本资料审核信息,副表
	 * @param userId 用户Id
	 * @return
	 * @author zhiliuang.lan
	 * @createDate 2017年6月22日12:33:27
	 */
	public ResultInfo updateCompanyBasicInfoAuditInfo(t_company_info_side companyInfoSide) {
		ResultInfo result = new ResultInfo();
		t_company_info_side companyInfo = findByID(companyInfoSide.id);
		//更新所有字段信息
		companyInfo.user_id = companyInfoSide.user_id;
		companyInfo.logo = companyInfoSide.logo;
		companyInfo.full_name = companyInfoSide.full_name;
		companyInfo.short_name = companyInfoSide.short_name;
		companyInfo.time = new Date();
		companyInfo.setClient(companyInfoSide.getClient());
		companyInfo.business_license_code = companyInfoSide.business_license_code;
		companyInfo.business_license_code_pic = companyInfoSide.business_license_code_pic;
		companyInfo.agent_name = companyInfoSide.agent_name;
		companyInfo.agent_mobile = companyInfoSide.agent_mobile;
		companyInfo.agent_tel = companyInfoSide.agent_tel;
		companyInfo.setCertificate_type(companyInfoSide.getCertificate_type());
		companyInfo.agent_card_number = companyInfoSide.agent_card_number;
		companyInfo.agent_card_on = companyInfoSide.agent_card_on;
		companyInfo.agent_card_under = companyInfoSide.agent_card_under;
		companyInfo.agent_address = companyInfoSide.agent_address;
		companyInfo.agent_email = companyInfoSide.agent_email;
		companyInfo.company_agent_person_proxy_pic = companyInfoSide.company_agent_person_proxy_pic;
		companyInfo.company_license_pic = companyInfoSide.company_license_pic;
		companyInfo.company_work_address = companyInfoSide.company_work_address;
		companyInfo.company_license_permit = companyInfoSide.company_license_permit;
		companyInfo.company_credit_card = companyInfoSide.company_credit_card;
		companyInfo.setLicense_card_type(companyInfoSide.getLicense_card_type());
		companyInfo.license_code = companyInfoSide.license_code;
		companyInfo.license_card_pic_on = companyInfoSide.license_card_pic_on;
		companyInfo.license_card_pic_under = companyInfoSide.license_card_pic_under;
		companyInfo.legal_person_name = companyInfoSide.legal_person_name;
		companyInfo.legal_person_mobile = companyInfoSide.legal_person_mobile;
		companyInfo.legal_person_tel = companyInfoSide.legal_person_tel;
		companyInfo.legal_person_address = companyInfoSide.legal_person_address;
		companyInfo.legal_person_email = companyInfoSide.legal_person_email;
		companyInfo.company_legal_person_proxy_pic = companyInfoSide.company_legal_person_proxy_pic;
		companyInfo.province_id = companyInfoSide.province_id;
		companyInfo.city_id = companyInfoSide.city_id;
		companyInfo.setCa_authentication_status(companyInfoSide.getCa_authentication_status());
		companyInfo.credit_point = companyInfoSide.credit_point;
		companyInfo.credit_level_id = companyInfoSide.credit_level_id;
		companyInfo.setMember_type(companyInfoSide.getMember_type());
		companyInfo.invest_member_time = companyInfoSide.invest_member_time;
		companyInfo.company_type_id = companyInfoSide.company_type_id;
		companyInfo.industry_type_id = companyInfoSide.industry_type_id;
		companyInfo.open_account = companyInfoSide.open_account;
		companyInfo.open_bank = companyInfoSide.open_bank;
		companyInfo.setIs_black(companyInfoSide.getIs_black());
		companyInfo.black_reason = companyInfoSide.black_reason;
		companyInfo.small_amount = companyInfoSide.small_amount;
		companyInfo.company_authenticate_status = companyInfoSide.company_authenticate_status;
		companyInfo.setBasic_info_audit_status(companyInfoSide.getBasic_info_audit_status());
		companyInfo.setAuthenticate_status(companyInfoSide.getAuthenticate_status());
		companyInfo.basic_info_score = companyInfoSide.basic_info_score;
		companyInfo.update_email_status = companyInfoSide.update_email_status;
		companyInfo.email_authorization_certificate_pic = companyInfoSide.email_authorization_certificate_pic;
		companyInfo.agent_status = companyInfoSide.agent_status;
		companyInfo.small_amount_pic = companyInfoSide.small_amount_pic;
		
		
		companyInfo.agent_account = companyInfoSide.agent_account;
		companyInfo.agent_back_mobile = companyInfoSide.agent_back_mobile;
		companyInfo.legal_account = companyInfoSide.legal_account;
		companyInfo.legal_back_mobile = companyInfoSide.legal_back_mobile;

		boolean isFlag = companyInfoSideDao.save(companyInfo);
		if (!isFlag) {
			result.code = -1;
			result.msg= "更新审核信息失败";
			LoggerUtil.error(true, "更新企业基本资料失败");
			return result;
		}
		result.code = 1;
		result.msg= "更新审核信息成功";
		
		return result;
	}
	
	/**
	 * 添加企业基本资料到附表
	 * @param id
	 * @param client
	 * @param fullName
	 * @param shortName
	 * @param businessLicenseCode
	 * @param agentName
	 * @param agentTel
	 * @param agentEmail
	 * @param agentMobile
	 * @return
	 * @author binghui.zhou
	 * @param company_type_id 
	 * @param samll_amount 
	 * @createDate 2017年6月22日
	 */
	public boolean addCompanyInfo(Long id, Client client, String fullName, String shortName, String businessLicenseCode,
			String agentName, String agentTel, String agentEmail, String agentMobile, long company_type_id, double samll_amount) {
		t_company_info_side side=new t_company_info_side();
		
		t_reddish_black reddish_black = reddishBlackService.findByCompanyName(fullName);
		if(reddish_black != null && reddish_black.getType() == ReddishBlack.BLACK){
			side.setIs_black(IsBlackCompany.IS_REDDISH);
		}
		side.user_id = id;
		side.setClient(client.PC);
		side.full_name = fullName;
		side.short_name = shortName;
		side.business_license_code = businessLicenseCode;
		side.agent_name = agentName;
		side.agent_tel = agentTel;
		side.agent_email = agentEmail;
		side.agent_mobile = agentMobile;
		side.time = new Date();
		side.small_amount = samll_amount;
		side.company_type_id = company_type_id;
		
		return companyInfoSideDao.save(side);
	}
	
	/**
	 * 企业认证全称校验
	 * @param trim
	 * @param id
	 * @return
	 * @author binghui.zhou
	 * @createDate 2017年6月29日
	 */
	public t_company_info_side checkCompanyFullName(String name, String id) {
		return companyInfoSideDao.checkCompanyFullName(name,id);
	}
	
	/**
	 * 营业执照号校验
	 * @param trim
	 * @param id
	 * @return
	 * @author binghui.zhou
	 * @createDate 2017年6月29日
	 */
	public t_company_info_side updateFindLicense(String code, String id) {
		return companyInfoSideDao.updateFindLicense(code,id);
	}
	
	/**
	 * 修改邮箱
	 * @param userId 用户ID
	 * @param email 邮箱
	 * @return
	 * @author binghui.zhou
	 * @createDate 2017年7月7日
	 */
	public boolean updateEmail(long userId, String email) {
		int in=companyInfoSideDao.updateEmail(userId,email);
		if (in<0){
			return false;
		}
		return true;
	}

	/**
	 * 查企业信息副表和对应的交易信用积分信息
	 * @param userId
	 * @return
	 * @author zhiliang.lan
	 * @createDate 2017年7月24日17:15:40
	 */
	public Map<String, Object> findCompanyInfoSideAndCreditLevelByUserId2(
			long userId) {
		return companyInfoSideDao.findCompanyInfoSideAndCreditLevelByUserId2(userId);
	}
	
	/**
	 * 修改手机号 
	 * @param id
	 * @param mobile 手机号
	 * @return
	 * @author binghui.zhou
	 * @createDate 2017年7月27日
	 */
	public ResultInfo updateUserMobile(long id, String mobile) {
		ResultInfo result=new ResultInfo();
		int type=companyInfoSideDao.updateUserMobile( id,  mobile);
		if (type < 1){
			result.code=-1;
			result.msg="修改手机失败";
			return result;
		}
		result.code=1;
		result.msg="修改手机成功";
		return result;
	}
	/**
	 * 更新CA状态
	 *
	 * @param id
	 * @param ca_authentication_status
	 * @return
	 * @author xiaojun
	 *@version 2017-9-27
	 */
	public ResultInfo updateUserCaAuthentication_status(long id, int ca_authentication_status) {
		ResultInfo result=new ResultInfo();
		int type=companyInfoSideDao.updateUserCaAuthentication_status( id,  ca_authentication_status);
		if (type < 1){
			result.code=-1;
			result.msg="CA状态更新失败！";
			return result;
		}
		result.code=1;
		result.msg="CA状态更新成功！";
		return result;
	}
	
	/**
	 * 基本资料信息校验
	 *
	 * @param userId 
	 * @param business_license_code_pic
	 * @param province_id
	 * @param city_id
	 * @param company_work_address
	 * @param company_license_permit
	 * @param open_bank
	 * @param open_account
	 * @param legal_person_name
	 * @param license_card_type
	 * @param license_code
	 * @param license_card_pic_on
	 * @param license_card_pic_under
	 * @param legal_person_mobile
	 * @param legal_person_tel
	 * @param legal_person_address
	 * @param legal_person_email
	 * @param company_legal_person_proxy_pic
	 * @param agent_name
	 * @param certificate_type
	 * @param agent_card_number
	 * @param agent_card_on
	 * @param agent_card_under
	 * @param agent_mobile
	 * @param agent_tel
	 * @param agent_email
	 * @param agent_address
	 * @param company_agent_person_proxy_pic
	 * @param legal_account 法定代表人银行卡号
	 * @param legal_back_mobile 法定代表人银行卡预留手机号
	 * @param agent_account 经办人银行卡号
	 * @param agent_back_mobile 经办人银行卡预留手机号
	 * @return
	 * @author xiaojun
	 *@version 2018-1-21
	 * @param anxinsign_url 
	 */
	public static ResultInfo validateBasicInfo(long userId,
			String business_license_code_pic, long province_id, long city_id,
			String company_work_address, String company_license_permit,
			String open_bank, String open_account, String legal_person_name,
			int license_card_type, String license_code,
			String license_card_pic_on, String license_card_pic_under,
			String legal_person_mobile, String legal_person_tel,
			String legal_person_address, String legal_person_email,
			String company_legal_person_proxy_pic, String agent_name,
			int certificate_type, String agent_card_number,
			String agent_card_on, String agent_card_under, String agent_mobile,
			String agent_tel, String agent_email, String agent_address,
			String company_agent_person_proxy_pic,String legal_account,
			String legal_back_mobile,String agent_account,String agent_back_mobile,int company_authenticate_status) {
		
		ResultInfo result = new ResultInfo();
		
		//--------------校验开始-----------------
		if(StringUtils.isBlank(business_license_code_pic)){
			result.code = -1;
			result.msg = "请上传营业执照图片";
			return result;
		}
		if( province_id == 0){
			result.code = -1;
			result.msg = "请选择住注册省份";
			return result;
		}
		if(city_id == 0){
			result.code = -1;
			result.msg = "请选择注册城市";
			return result;
		}
		if(StringUtils.isBlank(open_bank)){
			result.code = -1;
			result.msg = "请填写对公银行";
			return result;
		}
		if(StringUtils.isBlank(open_account)){
			result.code = -1;
			result.msg="请填写对公账号";
			return result;
		}
		//银行账号校验
		if(!StrUtil.isBankAccount(open_account)){
			result.code = -1;
			result.msg="对公账号格式不正确";
			return result;
		}
		
		
		if(StringUtils.isBlank(company_work_address)){
			result.code = -1;
			result.msg = "请填写企业常用办公地址";
			return result;
		}
		if(StringUtils.isBlank(company_license_permit)){
			result.code = -1;
			result.msg = "请上传企业开户许可证";
			return result;
		}
		if(StringUtils.isBlank(legal_person_name)){
			result.code = -1;
			result.msg = "请填写法定代表人代表姓名";
			return result;
		}
		/*经办人与法定代表人可以相同*/
		if(StringUtils.isBlank(license_code)){
			result.code = -1;
			result.msg = "请填写法定代表人身份证号";
			return result;
		}
		
		//身份证号校验,法定代表人
		boolean flag = StrUtil.checkIdentityCode(license_code);
		if(flag == false){
			result.code = -1;
			result.msg = "法定代表人代表身份证格式不正确";
			return result;
		}
		/*if(StringUtils.isBlank(legal_account)){
			result.code = -1;
			result.msg = "请填写法定代表人银行卡号";
			return result;
		}
		if(StringUtils.isBlank(legal_back_mobile)){
			result.code = -1;
			result.msg = "请填写法定代表人银行卡预留手机号";
			return result;
		}*/
		if(StringUtils.isBlank(license_card_pic_on)){
			result.code = -1;
			result.msg = "请上传法定代表人代表证件正面图片";
			return result;
		}
		if(StringUtils.isBlank(license_card_pic_under)){
			result.code = -1;
			result.msg="请上传法定代表人代表证件反面图片";
			return result;
		}
		if(StringUtils.isBlank(legal_person_mobile)){
			result.code = -1;
			result.msg="请填写法定代表人代表手机号码";
			return result;
		}
		if(!StrUtil.isMobileNum(legal_person_mobile)){
			result.code = -1;
			result.msg = "法定代表人手机号码不符合规范";
			return result;
		}
		if(StringUtils.isBlank(legal_person_tel)){
			result.code = -1;
			result.msg = "请填写法定代表人代表人固定电话";
			return result;
		}
		/*if(StringUtils.isBlank(legal_person_address)){
			result.code = -1;
			result.msg = "请填写法定代表人居住地址";
			return result;
		}*/
		
		if(StringUtils.isBlank(legal_person_email)){
			result.code = -1;
			result.msg = "请填写法定代表人代表人邮箱地址";
			return result;
		}
		/* 验证邮箱是否符合规范 */
		if (!StrUtil.isEmail(legal_person_email)) {
			result.code = -1;
			result.msg = "法定代表人邮箱地址不符合规范";
			return result;
		}
		if(StringUtils.isBlank(company_legal_person_proxy_pic)){
			result.code = -1;
			result.msg = "请上传法定代表人授权委托书图片";
			return result;
		}
		if(StringUtils.isBlank(agent_name)){
			result.code = -1;
			result.msg = "请填写经办人姓名";
			return result;
		}
		
		if(StringUtils.isBlank(agent_card_number)){
			result.code = -1;
			result.msg = "请填写经办人身份证号码";
			return result;
		}
		
		//身份证号校验,经办人
		boolean flag1 = StrUtil.checkIdentityCode(agent_card_number);
		if(flag1 == false){
			result.code = -1;
			result.msg = "经办人身份证格式不正确";
			return result;
		}
		/*if(StringUtils.isBlank(agent_account)){
			result.code = -1;
			result.msg = "请填写经办人银行卡号";
			return result;
		}
		if(StringUtils.isBlank(agent_back_mobile)){
			result.code = -1;
			result.msg = "请填写经办人银行卡预留手机号";
			return result;
		}*/
		
		if(StringUtils.isBlank(agent_card_on)){
			result.code = -1;
			result.msg = "请上传经办人证件图片正面";
			return result;
		}
		if(StringUtils.isBlank(agent_card_under)){
			result.code = -1;
			result.msg = "请上传经办人证件图片反面";
			return result;
		}
		//手机号需要判空和验证是否存在
		if(StringUtils.isBlank(agent_mobile)){
			result.code = -1;
			result.msg = "请填写经办人手机号码";
			return result;
		}
		if (userService.isMobileExistsExceptSelf(agent_mobile,userId,1)) {
			result.code = -1;
			result.msg = "手机号码已存在";
			return result;
		}
		if(!StrUtil.isMobileNum(agent_mobile)){
			result.code = -1;
			result.msg = "经办人手机号码不符合规范";
			return result;
		}
		
		if(StringUtils.isBlank(agent_tel)){
			result.code = -1;
			result.msg = "请填写经办人固定电话";
			return result;
		}
		if(StringUtils.isBlank(agent_email)){
			result.code = -1;
			result.msg = "请填写经办人邮箱地址";
			return result;
		}
		/* 判断邮箱是否存在 */
		if (userService.isEmailExistsExceptSelf(agent_email,userId)) {
			result.code = -1;
			result.msg = "经办人邮箱已存在";
			return result;
		}
		/* 验证邮箱是否符合规范 */
		if (!StrUtil.isEmail(agent_email)) {
			 	result.code = -1;
			result.msg = "经办人邮箱地址不符合规范";
			return result;
		}
		/*if(StringUtils.isBlank(agent_address)){
			result.code = -1;
			result.msg = "请填写经办人居住地址";
			return result;
		}*/
		
		/*if(company_authenticate_status !=1){
			result.code = -1;
			result.msg = "请先通过企业认证";
			return result;
		}*/
	/*	if(StringUtils.isBlank(company_agent_person_proxy_pic)){
			result.code = -1;
			result.msg = "请上传经办人授权委托书图片";
			return result;
		}*/
		
		//--------------校验结束-----------------
		
		result.code = 1;
		result.msg = "校验成功";
		
		return result;
	}

	/**
	 * 校验经办人信息 
	 * 
	 * @param agent_name
	 * @param agent_card_number
	 * @param agent_card_on
	 * @param agent_card_under
	 * @param agent_mobile
	 * @param agent_tel
	 * @param agent_email
	 * @param agent_address
	 * @param company_agent_person_proxy_pic
	 * @param sms_code
	 * @param password
	 * @return
	 * @author zhiliang.lan
	 * @param agent_account 
	 * @param agent_back_mobile 
	 * @createDate 2017年8月5日
	 */
	public ResultInfo validateAgentPersonInfo(long userId,int certificate_type, String agent_name,
			String agent_card_number, String agent_card_on,
			String agent_card_under, String agent_mobile, String agent_tel,
			String agent_email, String agent_address,
			String company_agent_person_proxy_pic, String sms_code,
			String password, String agent_back_mobile, String agent_account) {
		ResultInfo result = new ResultInfo();
		//----------校验开始----------------
		if(StringUtils.isBlank(agent_name)){
			result.code = -1;
			result.msg = "请填写经办人姓名";
			return result;
		}
		if(StringUtils.isBlank(agent_card_number)){
			result.code = -1;
			result.msg = "请填写经办人证件号码";
			return result;
		}
		if(StringUtils.isBlank(agent_card_on)){
			result.code = -1;
			result.msg = "请上传经办人证件正面图片";
			return result;
		}
		if(StringUtils.isBlank(agent_card_under)){
			result.code = -1;
			result.msg = "请上传经办人证件反面图片";
			return result;
		}
		if(StringUtils.isBlank(agent_mobile)){
			result.code = -1;
			result.msg = "请填写经办人手机号码";
			return result;
		}
		if(!StrUtil.isMobileNum(agent_mobile)){
			result.code = -1;
			result.msg = "经办人手机号码不符合规范";
			return result;
		}
		if (userService.isMobileExistsExceptSelf(agent_mobile,userId,1)) {
			result.code = -1;
			result.msg = "手机号码已存在";
			return result;
		}
		if(StringUtils.isBlank(agent_tel)){
			result.code = -1;
			result.msg = "请填写经办人固定电话";
			return result;
		}
		if (!StrUtil.isTelephone(agent_tel)){
			result.code = -1;
			result.msg = "经办人固定电话格式不正确";
			return result;
		}
		if(StringUtils.isBlank(agent_email)){
			result.code = -1;
			result.msg = "请填写经办人邮箱地址";
			return result;
		}
		if(!StrUtil.isEmail(agent_email)){
			result.code = -1;
			result.msg = "经办人邮箱地址不符合规范";
			return result;
		}
		/*if(StringUtils.isBlank(agent_address)){
			result.code = -1;
			result.msg = "请填写经办人居住地址";
			return result;
		}*/
		if(StringUtils.isBlank(company_agent_person_proxy_pic)){
			result.code = -1;
			result.msg = "请上传授权委托书图片";
			return result;
		}
		if(StringUtils.isBlank(sms_code)){
			result.code = -1;
			result.msg = "请填写短信验证码";
			return result;
		}
		if(StringUtils.isBlank(password)){
			result.code = -1;
			result.msg = "请填写密码";
			return result;
		}
		
		/*if(StringUtils.isBlank(agent_account)){
			result.code = -1;
			result.msg = "请填写银行卡号";
			return result;
		}
		if(StringUtils.isBlank(agent_back_mobile)){
			result.code = -1;
			result.msg = "请填写银行卡预留手机号码";
			return result;
		}*/
		boolean flag = StrUtil.isIdNum(agent_card_number);
		if(flag == false){
			result.code = -1;
			result.msg = "身份证号码格式不正确";
			return result;
		}
		//----------校验结束----------------
		result.code = 1;
		result.msg = "校验通过";
		
		return result;
	}
	/*
	 * 微信端校验经办人
	 */
	public ResultInfo wxValidateAgentPersonInfo(long userId,int certificate_type, String agent_name,
			String agent_card_number, String agent_card_on,
			String agent_card_under, String agent_mobile, String agent_tel,
			String agent_email, String agent_address,
			String company_agent_person_proxy_pic, String sms_code,
			String password, String anxinsign_url, String agent_back_mobile, String agent_account) {
		ResultInfo result = new ResultInfo();
		//----------校验开始----------------
		if(StringUtils.isBlank(agent_name)){
			result.code = -1;
			result.msg = "请填写经办人姓名";
			return result;
		}
		if(StringUtils.isBlank(agent_card_number)){
			result.code = -1;
			result.msg = "请填写经办人证件号码";
			return result;
		}
		if(StringUtils.isBlank(agent_card_on)){
			result.code = -1;
			result.msg = "请上传经办人证件正面图片";
			return result;
		}
		if(StringUtils.isBlank(agent_card_under)){
			result.code = -1;
			result.msg = "请上传经办人证件反面图片";
			return result;
		}
		if(StringUtils.isBlank(agent_mobile)){
			result.code = -1;
			result.msg = "请填写经办人手机号码";
			return result;
		}
		if(!StrUtil.isMobileNum(agent_mobile)){
			result.code = -1;
			result.msg = "经办人手机号码不符合规范";
			return result;
		}
		if (userService.isMobileExistsExceptSelf(agent_mobile,userId,1)) {
			result.code = -1;
			result.msg = "手机号码已存在";
			return result;
		}
		if(StringUtils.isBlank(agent_tel)){
			result.code = -1;
			result.msg = "请填写经办人固定电话";
			return result;
		}
		if (!StrUtil.isTelephone(agent_tel)){
			result.code = -1;
			result.msg = "经办人固定电话格式不正确";
			return result;
		}
		if(StringUtils.isBlank(agent_email)){
			result.code = -1;
			result.msg = "请填写经办人邮箱地址";
			return result;
		}
		if(!StrUtil.isEmail(agent_email)){
			result.code = -1;
			result.msg = "经办人邮箱地址不符合规范";
			return result;
		}
		/*if(StringUtils.isBlank(agent_address)){
			result.code = -1;
			result.msg = "请填写经办人居住地址";
			return result;
		}*/
/*		if(StringUtils.isBlank(company_agent_person_proxy_pic)){
			result.code = -1;
			result.msg = "请上传授权委托书图片";
			return result;
		}*/
		if(StringUtils.isBlank(sms_code)){
			result.code = -1;
			result.msg = "请填写短信验证码";
			return result;
		}
		if(StringUtils.isBlank(password)){
			result.code = -1;
			result.msg = "请填写密码";
			return result;
		}
		if(StringUtils.isBlank(anxinsign_url)){
			result.code = -1;
			result.msg = "请上传安心签用户信息修改申请表";
			return result;
		}
		/*if(StringUtils.isBlank(agent_account)){
			result.code = -1;
			result.msg = "请填写银行卡号";
			return result;
		}
		if(StringUtils.isBlank(agent_back_mobile)){
			result.code = -1;
			result.msg = "请填写银行卡预留手机号码";
			return result;
		}*/
		boolean flag = StrUtil.isIdNum(agent_card_number);
		if(flag == false){
			result.code = -1;
			result.msg = "身份证号码格式不正确";
			return result;
		}
		//----------校验结束----------------
		result.code = 1;
		result.msg = "校验通过";
		
		return result;
	}

	public ResultInfo validateLegalPersonInfo(long userId,
			int license_card_type, String legal_person_name,
			String license_code, String license_card_pic_on,
			String license_card_pic_under, String legal_person_mobile,
			String legal_person_tel, String legal_person_email,
			String legal_person_address, String company_legal_person_proxy_pic,
			String sms_code, String password, String legal_back_mobile, String legal_account) {
		
		ResultInfo result = new ResultInfo();
		//----------校验开始----------------
		if(StringUtils.isBlank(legal_person_name)){
			result.code = -1;
			result.msg = "请填写法定代表人姓名";
			return result;
		}
		if(StringUtils.isBlank(license_code)){
			result.code = -1;
			result.msg = "请填写法定代表人证件号码";
			return result;
		}
		if(StringUtils.isBlank(license_card_pic_on)){
			result.code = -1;
			result.msg = "请上传法定代表人证件正面图片";
			return result;
		}
		if(StringUtils.isBlank(license_card_pic_under)){
			result.code = -1;
			result.msg = "请上传法定代表人证件反面图片";
			return result;
		}
		if(StringUtils.isBlank(legal_person_mobile)){
			result.code = -1;
			result.msg = "请填写法定代表人手机号码";
			return result;
		}
		if(!StrUtil.isMobileNum(legal_person_mobile)){
			result.code = -1;
			result.msg = "法定代表人手机号码不符合规范";
			return result;
		}
		/*if (userService.isMobileExistsExceptSelf(legal_person_mobile,userId,1)) {
			result.code = -1;
			result.msg = "手机号码已存在";
			return result;
		}*/
		if(StringUtils.isBlank(legal_person_tel)){
			result.code = -1;
			result.msg = "请填写法定代表人固定电话";
			return result;
		}
		if (!StrUtil.isTelephone(legal_person_tel)){
			result.code = -1;
			result.msg = "法定代表人固定电话格式不正确";
			return result;
		}
		if(StringUtils.isBlank(legal_person_email)){
			result.code = -1;
			result.msg = "请填写法定代表人邮箱地址";
			return result;
		}
		if(!StrUtil.isEmail(legal_person_email)){
			result.code = -1;
			result.msg = "经办人邮箱地址不符合规范";
			return result;
		}
		/*if(StringUtils.isBlank(legal_person_address)){
			result.code = -1;
			result.msg = "请填写法定代表人居住地址";
			return result;
		}*/
		if(StringUtils.isBlank(company_legal_person_proxy_pic)){
			result.code = -1;
			result.msg = "请上传授权委托书图片";
			return result;
		}
		if(StringUtils.isBlank(sms_code)){
			result.code = -1;
			result.msg = "请填写短信验证码";
			return result;
		}
		if(StringUtils.isBlank(password)){
			result.code = -1;
			result.msg = "请填写密码";
			return result;
		}
		/*if(StringUtils.isBlank(legal_back_mobile)){
			result.code = -1;
			result.msg = "请填写法定代表人银行卡预留手机号码";
			return result;
		}
		if(StringUtils.isBlank(legal_account)){
			result.code = -1;
			result.msg = "请填写法定代表人银行卡号";
			return result;
		}
		*/
		boolean flag = StrUtil.isIdNum(license_code);
		if(flag == false){
			result.code = -1;
			result.msg = "身份证号码格式不正确";
			return result;
		}
		//----------校验结束----------------
		result.code = 1;
		result.msg = "校验通过";
		
		return result;
	}
	/**
	 * 微信审核法人修改
	 *
	 * @param userId
	 * @param license_card_type
	 * @param legal_person_name
	 * @param license_code
	 * @param license_card_pic_on
	 * @param license_card_pic_under
	 * @param legal_person_mobile
	 * @param legal_person_tel
	 * @param legal_person_email
	 * @param legal_person_address
	 * @param company_legal_person_proxy_pic
	 * @param sms_code
	 * @param password
	 * @param legal_back_mobile
	 * @param legal_account
	 * @param anxinsign_url
	 * @return
	 * @author xiaojun
	 *@version 2018年4月23日
	 */
	public ResultInfo wxValidateLegalPersonInfo(long userId,
			int license_card_type, String legal_person_name,
			String license_code, String license_card_pic_on,
			String license_card_pic_under, String legal_person_mobile,
			String legal_person_tel, String legal_person_email,
			String legal_person_address, String company_legal_person_proxy_pic,
			String sms_code, String password, String legal_back_mobile, String legal_account, String anxinsign_url) {
		
		ResultInfo result = new ResultInfo();
		//----------校验开始----------------
		if(StringUtils.isBlank(legal_person_name)){
			result.code = -1;
			result.msg = "请填写法定代表人姓名";
			return result;
		}
		if(StringUtils.isBlank(license_code)){
			result.code = -1;
			result.msg = "请填写法定代表人证件号码";
			return result;
		}
		if(StringUtils.isBlank(license_card_pic_on)){
			result.code = -1;
			result.msg = "请上传法定代表人证件正面图片";
			return result;
		}
		if(StringUtils.isBlank(license_card_pic_under)){
			result.code = -1;
			result.msg = "请上传法定代表人证件反面图片";
			return result;
		}
		if(StringUtils.isBlank(legal_person_mobile)){
			result.code = -1;
			result.msg = "请填写法定代表人手机号码";
			return result;
		}
		if(!StrUtil.isMobileNum(legal_person_mobile)){
			result.code = -1;
			result.msg = "经办人手机号码不符合规范";
			return result;
		}
		/*if (userService.isMobileExistsExceptSelf(legal_person_mobile,userId,1)) {
			result.code = -1;
			result.msg = "手机号码已存在";
			return result;
		}*/
		if(StringUtils.isBlank(legal_person_tel)){
			result.code = -1;
			result.msg = "请填写法定代表人固定电话";
			return result;
		}
		if (!StrUtil.isTelephone(legal_person_tel)){
			result.code = -1;
			result.msg = "法定代表人固定电话格式不正确";
			return result;
		}
		if(StringUtils.isBlank(legal_person_email)){
			result.code = -1;
			result.msg = "请填写法定代表人邮箱地址";
			return result;
		}
		if(!StrUtil.isEmail(legal_person_email)){
			result.code = -1;
			result.msg = "经办人邮箱地址不符合规范";
			return result;
		}
		/*if(StringUtils.isBlank(legal_person_address)){
			result.code = -1;
			result.msg = "请填写法定代表人居住地址";
			return result;
		}*/
		if(StringUtils.isBlank(company_legal_person_proxy_pic)){
			result.code = -1;
			result.msg = "请上传授权委托书图片";
			return result;
		}
		if(StringUtils.isBlank(sms_code)){
			result.code = -1;
			result.msg = "请填写短信验证码";
			return result;
		}
		if(StringUtils.isBlank(password)){
			result.code = -1;
			result.msg = "请填写密码";
			return result;
		}
		/*if(StringUtils.isBlank(legal_back_mobile)){
			result.code = -1;
			result.msg = "请填写法定代表人银行卡预留手机号码";
			return result;
		}
		if(StringUtils.isBlank(legal_account)){
			result.code = -1;
			result.msg = "请填写法定代表人银行卡号";
			return result;
		}*/
		/*if(StringUtils.isBlank(anxinsign_url)){
			result.code = -1;
			result.msg = "请上传安心签用户信息修改申请表";
			return result;
		}*/
		boolean flag = StrUtil.isIdNum(license_code);
		if(flag == false){
			result.code = -1;
			result.msg = "身份证号码格式不正确";
			return result;
		}
		//----------校验结束----------------
		result.code = 1;
		result.msg = "校验通过";
		
		return result;
	}
	
	/**
	 * 后台审核更新附表信息
	 * @param id
	 * @param score
	 * @return
	 * @author binghui.zhou
	 * @createDate 2017年8月24日
	 */
	public ResultInfo updateAuditInfo(Long id, int score,int status) {
		ResultInfo result = new ResultInfo();
		int type = companyInfoSideDao.updateAuditInfo(id,score,status);
		if (type < 1 ){
			result.code = -1;
			result.msg= "更新审核信息失败";
			LoggerUtil.error(true, "更新企业基本资料失败");
			return result;
		}
		result.code = 1;
		result.msg= "更新审核信息成功";
		
		return result;
	}
	
	/**
	 *	根据企业简称或全称和其企业类型获取企业信息
	 * @param company_full_name
	 * @param type
	 * @return
	 * @author LiangQiongfeng
	 *@version 2018-1-22 
	 */
	public t_company_info_side findByNameAndCode(String company_full_name, int type) {
		
		return companyInfoSideDao.findByNameAndCode(company_full_name,type);
	}

	/**
	 *	查询企业信息
	 * @param name 用户名，手机号，邮箱，企业名称
	 * @return
	 * @author Liangqiongfeng
	 *@version 2018-1-22 
	 */
	public t_company_info_side findByName(String name) {
		// TODO Auto-generated method stub
		return companyInfoSideDao.findByName(name);
	}

	/**
	 * 更新积分
	 * @param user_id
	 * @param score
	 * @return
	 * @author liaijun
	 *@version 2018年1月31日
	 */
    public int updateCred(long user_id,int score){
    	return companyInfoSideDao.updateCred(user_id, score);
    }

    
	/**
	 * 小额金额鉴定审核状态修改
	 *
	 * @param user_id 企业用户id
	 * @param status 需要更新的状态
	 * @param oldStatus 旧状态
	 * @return
	 * @author Liangqiongfeng
	 *@version 2018-1-31
	 * @param small_amount_pic 小额金额鉴定凭证
	 */
	public ResultInfo updateByAuthenticate(long user_id,int status,int oldStatus, String small_amount_pic) {
		
		return companyInfoSideDao.updateByAuthenticate(user_id,status,oldStatus,small_amount_pic);
	}
	
	/**
	 * 查询客户信息
	 *
	 * @param userId 企业用户id
	 * @return
	 * @author fanghanyong
	 *@version 2018-2-10
	 */
	public t_company_info_side findByUserId(long userId) {
		
		return super.findByColumn(" user_id = ?", userId);
	}

	/**
	 *	修改邮箱
	 * @param userId 当前用户id
	 * @param email 要修改的邮箱号
	 * @param company_legal_person_proxy_pic 委托书路径
	 * @return
	 * @author Liangqiongfeng
	 *@version 2018-2-13 
	 * @param status 
	 */
	public boolean updateEmail(long userId, String email,
			String email_authorization_certificate_pic, int status) {
		int in=companyInfoSideDao.updateEmail(userId,email,email_authorization_certificate_pic,status);
		if (in<0){
			return false;
		}
		return true;
	}

	/**
	 *	修改经办人信息申请审核
	 * @param user_id
	 * @param agent_mobile
	 * @param anxinsign_url
	 * @param agent_status 
	 * @return
	 * @author Liangqiongfeng
	 *@version 2018-3-13 
	 */
	public boolean updateAgent(long user_id, String agent_mobile,
			 int agent_status) {
		int in=companyInfoSideDao.updateAgent(user_id,agent_mobile,agent_status);
		if (in<0){
			return false;
		}
		return true;
	}
	

	/**
	 *基本资料-企业资料的校验
	 * @param business_license_code_pic 营业执照图片
	 * @param province_id
	 * @param city_id
	 * @param company_work_address
	 * @param company_license_permit
	 * @param open_bank
	 * @param open_account
	 * @return
	 * @author lqf
	 *@version 2018-4-26 
	 */
	public ResultInfo enterPriseValidate(
			String business_license_code_pic, Long province_id, Long city_id,
			String company_work_address, String company_license_permit,
			String open_bank, String open_account) {
		
		ResultInfo result = new ResultInfo();
		
		//--------------校验开始-----------------
		if(StringUtils.isBlank(business_license_code_pic)){
			result.code = -1;
			result.msg = "请上传营业执照图片";
			return result;
		}
		if( province_id == 0){
			result.code = -1;
			result.msg = "请选择住注册省份";
			return result;
		}
		if(city_id == 0){
			result.code = -1;
			result.msg = "请选择注册城市";
			return result;
		}
		if(StringUtils.isBlank(open_bank)){
			result.code = -1;
			result.msg = "请填写对公银行";
			return result;
		}
		if(StringUtils.isBlank(open_account)){
			result.code = -1;
			result.msg="请填写对公账号";
			return result;
		}
		//银行账号校验
		if(!StrUtil.isBankAccount(open_account)){
			result.code = -1;
			result.msg="对公账号格式不正确";
			return result;
		}
		
		
		if(StringUtils.isBlank(company_work_address)){
			result.code = -1;
			result.msg = "请填写企业常用办公地址";
			return result;
		}
		if(StringUtils.isBlank(company_license_permit)){
			result.code = -1;
			result.msg = "请上传企业开户许可证";
			return result;
		}
		result.code = 1;
		result.msg = "校验通过";
		return result;
	}


	/**
	 *修改企业资料
	 * @param companyInfo
	 * @return
	 * @author lqf
	 *@version 2018-4-26 
	 * @param userId 
	 */
	public ResultInfo toUpdateEnterprise(long userId, t_company_info_side companyInfo) {
		
		ResultInfo result = new ResultInfo();
		
		t_company_info_side companyInfoSide = companyInfoSideDao.findByID(companyInfo.id);
		
		if(companyInfoSide == null){
			result.code = -1;
			result.msg = "获取不到企业信息";
			return result;
		}
		companyInfoSide.user_id = userId;
		companyInfoSide.business_license_code_pic = companyInfo.business_license_code_pic;
		companyInfoSide.province_id = companyInfo.province_id;
		companyInfoSide.city_id = companyInfo.city_id;
		companyInfoSide.company_work_address = companyInfo.company_work_address;
		companyInfoSide.company_license_permit = companyInfo.company_license_permit;
		companyInfoSide.open_bank = companyInfo.open_bank;
		companyInfoSide.open_account = companyInfo.open_account;
		
		boolean isFlag = companyInfoSideDao.save(companyInfoSide);
		if (!isFlag) {
			result.code = -1;
			result.msg= "更新企业基本资料企业资料信息失败";
			LoggerUtil.error(true, "更新企业基本资料企业资料信息失败");
			return result;
		}
		result.code = 1;
		result.msg= "更新企业基本资料企业资料信息成功";
		
		return result;
	}

	/**
	 * 修改企业资料-法定代表人信息
	 * @param legal_person_name
	 * @param license_card_type
	 * @param license_code
	 * @param license_card_pic_on
	 * @param license_card_pic_under
	 * @param legal_person_mobile
	 * @param legal_person_tel
	 * @param legal_person_address
	 * @param legal_person_email
	 * @param company_legal_person_proxy_pic
	 * @return
	 * @author lqf
	 *@version 2018-4-26 
	 * @param legal_back_mobile 
	 * @param legal_account 
	 */
	public ResultInfo representAtiveValidate(String legal_person_name,
			int license_card_type, String license_code,
			String license_card_pic_on, String license_card_pic_under,
			String legal_person_mobile, String legal_person_tel,
			String legal_person_address, String legal_person_email,
			String company_legal_person_proxy_pic, String legal_account, String legal_back_mobile) {
		
		ResultInfo result = new ResultInfo();
		
		if(StringUtils.isBlank(legal_person_name)){
			result.code = -1;
			result.msg = "请填写法定代表人代表姓名";
			return result;
		}
		/*经办人与法定代表人可以相同*/
		if(StringUtils.isBlank(license_code)){
			result.code = -1;
			result.msg = "请填写法定代表人身份证号";
			return result;
		}
		
		//身份证号校验,法定代表人
		boolean flag = StrUtil.checkIdentityCode(license_code);
		if(flag == false){
			result.code = -1;
			result.msg = "法定代表人代表身份证格式不正确";
			return result;
		}
		/*if(StringUtils.isBlank(legal_account)){
			result.code = -1;
			result.msg = "请填写法定代表人银行卡号";
			return result;
		}
		if(StringUtils.isBlank(legal_back_mobile)){
			result.code = -1;
			result.msg = "请填写法定代表人银行卡预留手机号";
			return result;
		}*/
		if(StringUtils.isBlank(license_card_pic_on)){
			result.code = -1;
			result.msg = "请上传法定代表人代表证件正面图片";
			return result;
		}
		if(StringUtils.isBlank(license_card_pic_under)){
			result.code = -1;
			result.msg="请上传法定代表人代表证件反面图片";
			return result;
		}
		if(StringUtils.isBlank(legal_person_mobile)){
			result.code = -1;
			result.msg="请填写法定代表人代表手机号码";
			return result;
		}
		if(!StrUtil.isMobileNum(legal_person_mobile)){
			result.code = -1;
			result.msg = "法定代表人手机号码不符合规范";
			return result;
		}
		if(StringUtils.isBlank(legal_person_tel)){
			result.code = -1;
			result.msg = "请填写法定代表人代表人固定电话";
			return result;
		}
		/*if(StringUtils.isBlank(legal_person_address)){
			result.code = -1;
			result.msg = "请填写法定代表人居住地址";
			return result;
		}
		*/
		if(StringUtils.isBlank(legal_person_email)){
			result.code = -1;
			result.msg = "请填写法定代表人代表人邮箱地址";
			return result;
		}
		/* 验证邮箱是否符合规范 */
		if (!StrUtil.isEmail(legal_person_email)) {
			result.code = -1;
			result.msg = "法定代表人邮箱地址不符合规范";
			return result;
		}
		if(StringUtils.isBlank(company_legal_person_proxy_pic)){
			result.code = -1;
			result.msg = "请上传法定代表人授权委托书图片";
			return result;
		}
		result.code = 1;
		result.msg = "校验通过";
		return result;
	}

	/**
	 * 基本资料-法定代表人资料
	 * @param userId
	 * @param companyInfo
	 * @return
	 * @author lqf
	 *@version 2018-4-26 
	 */
	public ResultInfo toUpdateRepresentAtive(long userId,
			t_company_info_side companyInfo) {
		
		ResultInfo result = new ResultInfo();
		
		t_company_info_side companyInfoSide = companyInfoSideDao.findByID(companyInfo.id);
		
		if(companyInfoSide == null){
			result.code = -1;
			result.msg = "获取不到企业信息";
			return result;
		}
		companyInfoSide.user_id = userId;
		companyInfoSide.legal_person_name = companyInfo.legal_person_name;
		companyInfoSide.license_code = companyInfo.license_code;
		companyInfoSide.legal_account = companyInfo.legal_account;
		companyInfoSide.legal_back_mobile = companyInfo.legal_back_mobile;
		companyInfoSide.license_card_pic_on = companyInfo.license_card_pic_on;
		companyInfoSide.license_card_pic_under = companyInfo.license_card_pic_under;
		companyInfoSide.legal_person_mobile = companyInfo.legal_person_mobile;
		companyInfoSide.legal_person_tel = companyInfo.legal_person_tel;
		companyInfoSide.legal_person_address = companyInfo.legal_person_address;
		companyInfoSide.legal_person_email = companyInfo.legal_person_email;
		companyInfoSide.company_legal_person_proxy_pic = companyInfo.company_legal_person_proxy_pic;
		
		boolean isFlag = companyInfoSideDao.save(companyInfoSide);
		if (!isFlag) {
			result.code = -1;
			result.msg= "更新企业基本资料法定代表人信息失败";
			LoggerUtil.error(true, "更新企业基本资料法定代表人信息失败");
			return result;
		}
		result.code = 1;
		result.msg= "更新企业基本资料法定代表人信息成功";
		
		return result;
	}

	/**
	 * 基本资料-企业经办人信息
	 * @param agent_name
	 * @param certificate_type
	 * @param agent_card_number
	 * @param agent_card_on
	 * @param agent_card_under
	 * @param agent_mobile
	 * @param agent_tel
	 * @param agent_email
	 * @param agent_address
	 * @param company_agent_person_proxy_pic
	 * @param agent_account
	 * @param agent_back_mobile
	 * @param company_authenticate_status
	 * @param anxinsign_url
	 * @return
	 * @author lqf
	 *@version 2018-4-26 
	 * @param userId 
	 */
	public ResultInfo operatorValidate(long userId, String agent_name, int certificate_type,
			String agent_card_number, String agent_card_on,
			String agent_card_under, String agent_mobile, String agent_tel,
			String agent_email, String agent_address,
			String company_agent_person_proxy_pic, String agent_account,
			String agent_back_mobile, int company_authenticate_status) {
		
		ResultInfo result = new ResultInfo();
		
		if(StringUtils.isBlank(agent_name)){
			result.code = -1;
			result.msg = "请填写经办人姓名";
			return result;
		}
		
		if(StringUtils.isBlank(agent_card_number)){
			result.code = -1;
			result.msg = "请填写经办人身份证号码";
			return result;
		}
		
		//身份证号校验,经办人
		boolean flag1 = StrUtil.checkIdentityCode(agent_card_number);
		if(flag1 == false){
			result.code = -1;
			result.msg = "经办人身份证格式不正确";
			return result;
		}
		/*if(StringUtils.isBlank(agent_account)){
			result.code = -1;
			result.msg = "请填写经办人银行卡号";
			return result;
		}
		if(StringUtils.isBlank(agent_back_mobile)){
			result.code = -1;
			result.msg = "请填写经办人银行卡预留手机号";
			return result;
		}*/
		
		if(StringUtils.isBlank(agent_card_on)){
			result.code = -1;
			result.msg = "请上传经办人证件图片正面";
			return result;
		}
		if(StringUtils.isBlank(agent_card_under)){
			result.code = -1;
			result.msg = "请上传经办人证件图片反面";
			return result;
		}
		//手机号需要判空和验证是否存在
		if(StringUtils.isBlank(agent_mobile)){
			result.code = -1;
			result.msg = "请填写经办人手机号码";
			return result;
		}
		if (userService.isMobileExistsExceptSelf(agent_mobile,userId,1)) {
			result.code = -1;
			result.msg = "手机号码已存在";
			return result;
		}
		if(!StrUtil.isMobileNum(agent_mobile)){
			result.code = -1;
			result.msg = "经办人手机号码不符合规范";
			return result;
		}
		
		if(StringUtils.isBlank(agent_tel)){
			result.code = -1;
			result.msg = "请填写经办人固定电话";
			return result;
		}
		if(StringUtils.isBlank(agent_email)){
			result.code = -1;
			result.msg = "请填写经办人邮箱地址";
			return result;
		}
		/* 判断邮箱是否存在 */
		if (userService.isEmailExistsExceptSelf(agent_email,userId)) {
			result.code = -1;
			result.msg = "经办人邮箱已存在";
			return result;
		}
		/* 验证邮箱是否符合规范 */
		if (!StrUtil.isEmail(agent_email)) {
			 	result.code = -1;
			result.msg = "经办人邮箱地址不符合规范";
			return result;
		}
		/*if(StringUtils.isBlank(agent_address)){
			result.code = -1;
			result.msg = "请填写经办人居住地址";
			return result;
		}*/
		
		
		result.code = 1;
		result.msg = "校验成功";
		
		return result;
	}

	/**
	 *	基本资料-经办人信息修改
	 * @param userId
	 * @param companyInfo
	 * @return
	 * @author lqf
	 *@version 2018-4-26 
	 */
	public ResultInfo toUpdateOperator(long userId,String agent_name, String agent_card_number,String agent_account, 
			String agent_back_mobile,String agent_card_on, String agent_card_under, String agent_mobile, String agent_tel,
			String agent_email, String agent_address, String company_agent_person_proxy_pic,
			int certificate_type,int company_authenticate_status) {
		
		ResultInfo result = new ResultInfo();
		t_company_info_side companyInfoSide = companyInfoSideDao.findCompanyInfoSideByUserId(userId);
		if (companyInfoSide == null) {
			result.code = -1;
			result.msg = "获取不到用户企业信息";
			return result;
		}
		companyInfoSide.agent_name  =  agent_name;                    
		companyInfoSide.agent_card_number  =  agent_card_number;                 
		companyInfoSide.agent_card_on   =  agent_card_on;                    
		companyInfoSide.agent_card_under  =  agent_card_under;                  
		companyInfoSide.agent_mobile  =  agent_mobile;                      
		companyInfoSide.agent_tel  =  agent_tel;                         
		companyInfoSide.agent_email  =  agent_email;                       
		companyInfoSide.agent_address  =  agent_address;                     
		companyInfoSide.company_agent_person_proxy_pic  =  company_agent_person_proxy_pic;    
		companyInfoSide.agent_account  =  agent_account;                     
		companyInfoSide.agent_back_mobile  =  agent_back_mobile;               
		companyInfoSide.company_authenticate_status  =  company_authenticate_status;     
		
		//设置两个证件类型
		companyInfoSide.setCertificate_type(CertificateType.getEnum(certificate_type));
    	//company_authenticate_status = CompanyAuthenticateStatus.PASS_YES.code;
		companyInfoSide.time = new Date();
		
		boolean isFlag = companyInfoSideDao.save(companyInfoSide);
		if (!isFlag) {
			result.code = -1;
			result.msg= "更新企业基本资料经办人信息失败";
			LoggerUtil.error(true, "更新企业基本资料经办人信息失败");
			return result;
		}
		result.code = 1;
		result.msg= "更新企业基本资料经办人信息成功";
		
		return result;
		
		
		
		
	}
	
	/**
	 *	校验修改的信息是否需要上传安心签申请表
	 * @param user_id
	 * @param companyInfo
	 * @param anxinsign_url
	 * @return
	 * @author lqf
	 *@version 2018-4-28 
	 */
	public  ResultInfo anxinsignValedate(long user_id,String agent_card_number,
			String agent_mobile,String agent_tel,String agent_name) {

		ResultInfo result = new ResultInfo();
		
		t_company_info_side companyInfoSide = companyInfoSideDao.findCompanyInfoSideByUserId(user_id);
		
		if(companyInfoSide == null){
			result.code = -1;
			result.msg = "查询不到用户企业信息";
			return result;
		}
		
		boolean flag = false;
		
		//修改了经办人手机号码
		if(StringUtils.isNotBlank(companyInfoSide.agent_mobile)&& StringUtils.isNotBlank(agent_mobile)&&  !(companyInfoSide.agent_mobile).equals(agent_mobile)){
			flag = true;
		}
		
		//修改了经办人电话号码
		if(StringUtils.isNotBlank(companyInfoSide.agent_tel) && StringUtils.isNotBlank(agent_tel) && !(companyInfoSide.agent_tel).equals(agent_tel)){
			flag = true;
		}
		
		//修改了经办人姓名
		if(StringUtils.isNotBlank(companyInfoSide.agent_name) && StringUtils.isNotBlank(agent_name) && !(companyInfoSide.agent_name).equals(agent_name)){
			flag = true;
		}
		
		//修改了经办人身份证号码
		if(StringUtils.isNotBlank(companyInfoSide.agent_card_number) && StringUtils.isNotBlank(agent_card_number) &&  !(companyInfoSide.agent_card_number).equals(agent_card_number)){
			flag = true;
		}
		
		if(flag){
			result.code = -1;
			result.msg = "请先上传安心签用户信息修改申请表";
			return result;
		}
		result.code = 1;
		result.msg = "校验通过";
				
		return result;
	}
	
	/**
	 *	校验法定代表人修改的信息是否需要上传安心签申请表
	 * @param user_id
	 * @param companyInfo
	 * @param anxinsign_url
	 * @return
	 * @author lqf
	 *@version 2018-4-28 
	 */
	public  ResultInfo anxinsignValedateOfLogel(long user_id,String license_code,
			String legal_person_mobile,String legal_person_tel,String legal_person_name) {
		
		ResultInfo result = new ResultInfo();
		
		t_company_info_side companyInfoSide = companyInfoSideDao.findCompanyInfoSideByUserId(user_id);
		
		if(companyInfoSide == null){
			result.code = -1;
			result.msg = "查询不到用户企业信息";
			return result;
		}
		
		boolean flag = false;
		
		//修改了经办人手机号码
		if(StringUtils.isNotBlank(companyInfoSide.legal_person_mobile)&& StringUtils.isNotBlank(legal_person_mobile)&&  !(companyInfoSide.legal_person_mobile).equals(legal_person_mobile)){
			flag = true;
		}
		
		//修改了经办人电话号码
		if(StringUtils.isNotBlank(companyInfoSide.legal_person_tel) && StringUtils.isNotBlank(legal_person_tel) && !(companyInfoSide.legal_person_tel).equals(legal_person_tel)){
			flag = true;
		}
		
		//修改了经办人姓名
		if(StringUtils.isNotBlank(companyInfoSide.legal_person_name) && StringUtils.isNotBlank(legal_person_name) && !(companyInfoSide.legal_person_name).equals(legal_person_name)){
			flag = true;
		}
		
		//修改了经办人身份证号码
		if(StringUtils.isNotBlank(companyInfoSide.license_code) && StringUtils.isNotBlank(license_code) &&  !(companyInfoSide.license_code).equals(license_code)){
			flag = true;
		}
		
		if(flag){
			result.code = -1;
			result.msg = "请先上传安心签用户信息修改申请表";
			return result;
		}
		result.code = 1;
		result.msg = "校验通过";
		
		return result;
	}
	
	/**
	 * 修改企业基本资料审核信息,副表
	 * @return
	 * @author lqf
	 * @createDate 2018-04-28
	 */
	public ResultInfo updateCompanyBasicInfo(long userId,String business_license_code_pic, 
			long province_id, long city_id, String company_work_address, 
			String company_license_permit, String open_bank, String open_account, 
			String legal_person_name, int license_card_type, String license_code, 
			String license_card_pic_on, String license_card_pic_under, String legal_person_mobile, 
			String legal_person_tel, String legal_person_address, String legal_person_email, 
			String company_legal_person_proxy_pic, String agent_name, int certificate_type, 
			String agent_card_number, String agent_card_on, String agent_card_under, 
			String agent_mobile, String agent_tel, String agent_email, String agent_address, 
			String company_agent_person_proxy_pic,String legal_account ,String legal_back_mobile,
			String agent_account,String agent_back_mobile,int company_authenticate_status) {
		
		ResultInfo result = new ResultInfo();
		
		t_company_info_side companyInfo = companyInfoSideDao.findCompanyInfoSideByUserId(userId);
		if (companyInfo == null ) {
			result.code = -1;
			result.msg = "获取不到用户企业信息";
			return result;
		}
		//更新所有字段信息
		companyInfo.time = new Date();
		companyInfo.business_license_code_pic = business_license_code_pic;
		companyInfo.agent_name = agent_name;
		companyInfo.agent_mobile = agent_mobile;
		companyInfo.agent_tel = agent_tel;
		companyInfo.setCertificate_type(CertificateType.getEnum(certificate_type));
		companyInfo.agent_card_number = agent_card_number;
		companyInfo.agent_card_on = agent_card_on;
		companyInfo.agent_card_under = agent_card_under;
		companyInfo.agent_address = agent_address;
		companyInfo.agent_email = agent_email;
		companyInfo.company_agent_person_proxy_pic = company_agent_person_proxy_pic;
		companyInfo.company_work_address = company_work_address;
		companyInfo.company_license_permit = company_license_permit;
		companyInfo.setLicense_card_type(CertificateType.getEnum(license_card_type));
		companyInfo.license_code = license_code;
		companyInfo.license_card_pic_on = license_card_pic_on;
		companyInfo.license_card_pic_under = license_card_pic_under;
		companyInfo.legal_person_name = legal_person_name;
		companyInfo.legal_person_mobile = legal_person_mobile;
		companyInfo.legal_person_tel = legal_person_tel;
		companyInfo.legal_person_address = legal_person_address;
		companyInfo.legal_person_email = legal_person_email;
		companyInfo.company_legal_person_proxy_pic = company_legal_person_proxy_pic;
		companyInfo.province_id = province_id;
		companyInfo.city_id = city_id;
		
		companyInfo.company_authenticate_status = company_authenticate_status;
		
		boolean isFlag = companyInfoSideDao.save(companyInfo);
		if (!isFlag) {
			result.code = -1;
			result.msg= "更新审核信息失败";
			LoggerUtil.error(true, "更新企业基本资料失败");
			return result;
		}
		result.code = 1;
		result.msg= "更新审核信息成功";
		
		return result;
	}

	/**
	 * 根据企业全称查询企业用户信息
	 * @param str
	 * @return
	 * @author liangqiongfeng
	 *@version 2018-5-10 
	 */
	public t_company_info_side findByCompanyName(String companyName) {
		// TODO Auto-generated method stub
		return companyInfoSideDao.findByCompanyName(companyName);
	}

	/**
	 *	查询企业会员信息
	 * @param userId
	 * @return
	 * @author Liangqiongfeng
	 *@version 2018-3-26 
	 */
	public CompanyUserBean findCompanyBeanByUserID(long userId) {
		
		return companyInfoSideDao.findCompanyBeanByUserID(userId);
	}


	/**
	 *	企业会员的一键打包下载
	 * @param companyInfo
	 * @return
	 * @author Liangqiongfeng
	 *@version 2018-3-26 
	 */
	public String[] getFileUrl(t_company_info_side companyInfo) {
		// 获取文件的相关信息

		// 获取营业执照资料
		String financialData = companyInfo.business_license_code_pic;
		String[] path = new String[12];
		if (StringUtils.isNotBlank(financialData)) {
			 
			path[0] = financialData;
		}
		// 获取经办人证件正面
		String incomeTax = companyInfo.agent_card_on;
		if (StringUtils.isNotBlank(incomeTax)) {
			path[1] = incomeTax;
		}
		// 获取经办人证件反面
		String bankStatement = companyInfo.agent_card_under;
		if (StringUtils.isNotBlank(bankStatement)) {
			path[2] = bankStatement;
		}
		// 获取企业法定代表人授权委托书图片
		String utilityBill = companyInfo.company_legal_person_proxy_pic;
		if (StringUtils.isNotBlank(utilityBill)) {
			path[3] = utilityBill;
		}
		// 企业经办人（代理人）授权委托书图片
		String paySheet = companyInfo.company_agent_person_proxy_pic;
		if (StringUtils.isNotBlank(paySheet)) {
			path[4] = paySheet;
		}
			
		// 获取企业营业执照的图片
		String purchaseSaleContracts = companyInfo.company_license_pic;
		if (StringUtils.isNotBlank(purchaseSaleContracts)) {
			path[5] = purchaseSaleContracts;
		}
		// 获取企业开户许可证 
		String finCreditInfo = companyInfo.company_license_permit;
		if (StringUtils.isNotBlank(finCreditInfo)) {
			path[6] = finCreditInfo;
		}
		// 获取法定代表人证件的正面
		String otherInfo = companyInfo.license_card_pic_on;
		if (StringUtils.isNotBlank(otherInfo)) {
			path[7] = otherInfo;
		}
		
		//获取法定代表人证件的背面
		String license_card_pic_under = companyInfo.license_card_pic_under;
		if (StringUtils.isNotBlank(license_card_pic_under)) {
			path[8] = license_card_pic_under;
		}
		//获取法定代表人证件的背面
		String small_amount_pic = companyInfo.small_amount_pic;
		if (StringUtils.isNotBlank(small_amount_pic)) {
			path[9] = small_amount_pic;
		}
		return path;
	}



	/**
	 *	放款人的一键打包下载
	 * @param companyInfo
	 * @return
	 * @author Liangqiongfeng
	 *@version 2018-3-26 
	 */
	public String[] getFileUrl(t_company_info_side companyInfo,t_credit_limit creditLimit) {
		// 获取文件的相关信息

		// 获取营业执照资料
		String business_license_code_pic = companyInfo.business_license_code_pic;
		String[] path = new String[20];
		if (StringUtils.isNotBlank(business_license_code_pic)) {
			 
			path[0] = business_license_code_pic;
		}
		// 获取经办人证件正面
		String agent_card_on = companyInfo.agent_card_on;
		if (StringUtils.isNotBlank(agent_card_on)) {
			path[1] = agent_card_on;
		}
		// 获取经办人证件反面
		String agent_card_under = companyInfo.agent_card_under;
		if (StringUtils.isNotBlank(agent_card_under)) {
			path[2] = agent_card_under;
		}
		// 获取企业法定代表人授权委托书图片
		String company_legal_person_proxy_pic = companyInfo.company_legal_person_proxy_pic;
		if (StringUtils.isNotBlank(company_legal_person_proxy_pic)) {
			path[3] = company_legal_person_proxy_pic;
		}
		// 企业经办人（代理人）授权委托书图片
		String company_agent_person_proxy_pic = companyInfo.company_agent_person_proxy_pic;
		if (StringUtils.isNotBlank(company_agent_person_proxy_pic)) {
			path[4] = company_agent_person_proxy_pic;
		}
			
		// 获取企业营业执照的图片
		String company_license_pic = companyInfo.company_license_pic;
		if (StringUtils.isNotBlank(company_license_pic)) {
			path[5] = company_license_pic;
		}
		// 获取企业开户许可证 
		String company_license_permit = companyInfo.company_license_permit;
		if (StringUtils.isNotBlank(company_license_permit)) {
			path[6] = company_license_permit;
		}
		// 获取法定代表人证件的正面
		String license_card_pic_on = companyInfo.license_card_pic_on;
		if (StringUtils.isNotBlank(license_card_pic_on)) {
			path[7] = license_card_pic_on;
		}
		
		//获取法定代表人证件的背面
		String license_card_pic_under = companyInfo.license_card_pic_under;
		if (StringUtils.isNotBlank(license_card_pic_under)) {
			path[8] = license_card_pic_under;
		}
		//获取法定代表人证件的背面
		String small_amount_pic = companyInfo.small_amount_pic;
		if (StringUtils.isNotBlank(small_amount_pic)) {
			path[9] = small_amount_pic;
		}
		// 获取财务资料
		String financialData = creditLimit.financial_data;
		if (StringUtils.isNotBlank(financialData)) {
			 
			path[10] = financialData;
		}
		// 获取所得税清缴报表
		String incomeTax = creditLimit.income_tax;
		if (StringUtils.isNotBlank(incomeTax)) {
			path[11] = incomeTax;
		}
		// 获取银行对账单
		String bankStatement = creditLimit.bank_statement;
		if (StringUtils.isNotBlank(bankStatement)) {
			path[12] = bankStatement;
		}
		// 获取水电费账单
		String utilityBill = creditLimit.utility_bill;
		if (StringUtils.isNotBlank(utilityBill)) {
			path[13] = utilityBill;
		}
		// 获取工资表和社保表单
		String paySheet = creditLimit.pay_sheet;
		if (StringUtils.isNotBlank(paySheet)) {
			path[14] = paySheet;
		}
			
		// 获取购销合同
		String purchaseSaleContracts = creditLimit.purchase_sale_contracts;
		if (StringUtils.isNotBlank(purchaseSaleContracts)) {
			path[15] = purchaseSaleContracts;
		}
		// 获取融通增信资料
		String finCreditInfo = creditLimit.financing_credit_information;
		if (StringUtils.isNotBlank(finCreditInfo)) {
			path[16] = finCreditInfo;
		}
		// 获取其他资料
		String otherInfo = creditLimit.other_information;
		if (StringUtils.isNotBlank(otherInfo)) {
			path[17] = otherInfo;
		}
		return path;
	}


}
